import os
import sys
import cv2
from tqdm import tqdm
from os import path
import subprocess
import shutil
import platform

basePath = os.path.dirname(os.path.abspath(__file__))
os.environ["PATH"] = os.path.join(basePath, "ffmpeg/bin/") + ";" + os.environ["PATH"]
wav2lipFolderName = 'Wav2Lip'
gfpganFolderName = 'GFPGAN'
wav2lipPath = os.path.join(basePath, wav2lipFolderName)
gfpganPath = os.path.join(basePath, gfpganFolderName)
sys.path.append(wav2lipPath)
sys.path.append(gfpganPath)

outputPath = basePath + '/outputs'

if not os.path.exists(outputPath):
    os.makedirs(outputPath)
from Wav2Lip.inference import main as wav2Lip_main



def run(face_path, audio_path):
    wav2Lip_main(face_path, audio_path, wav2lip_gan=True)
    # to_frame()
    from GFPGAN.inference_gfpgan import main as gfpgan_main
    # gfpgan_main(outputPath + '/frames', outputPath, bg_upsampler=None)  # 修复图像
    # concat_frame()
    pass


inputAudioPath = basePath + '/inputs/kim_audio.mp3'
# inputVideoPath = basePath + '/inputs/kimk_7s_raw.mp4'
inputVideoPath = basePath + '/inputs/0000.jpg'

if __name__ == "__main__":
    run(inputVideoPath, inputAudioPath)
    pass
